<?php
require_once 'database.class.php';
//require_once 'autentificare.php';

$a = session_id();
if(empty($a)) session_start();


function is_logat()
{
    
    
    if(!isset($_COOKIE["pu"])){
        
        
    }
    else{
        
    $a=$_SESSION['user'];
    $b=$_SESSION['pass'] ;
    
    $_SESSION['logat']="NU";
    $_SESSION["log_err"]='';
//    $pass_cookie = substr( $_COOKIE['pu'],0,31  );
//    $user_cookie = substr( $_COOKIE['pu'],32 );
    echo $_COOKIE["pu"];
    die("<br/> stop");
    
    if($a == '' || $b == '')
    {
        echo "Va rugam completati campurile";
        echo '<form action="index.php" >
            <input type="Submit" value="Pagina principala"/>
            ';
        return 0;
    }    
    else
    {
        $sql_login = "Select * from utilizatori where username='$a'";
        $rezultat = mysql_query($sql_login);
        $rows = mysql_num_rows($rezultat);

        if( $rows == 0 )
            return "user_inexistent";


        if( $rows != 1 )
            return "user_inexistent";

        $row = mysql_fetch_array($rezultat);


        if( $row['parola'] != $b || strlen($b) != 32)
            return "parola_gresita";
        else
            if( $row['activ'] == 0 )
                return "cont_inactiv";
            else
            {

                if( $row['grup'] == 1 )    
                    $_SESSION['logat']="user";

                if( $row['grup'] == 0)
                    $_SESSION['logat']="admin";

                if($_SESSION['logat'] == "admin")
                    return "admin";    
                else
                    return "user";
            }       
    }
    }
}


?>
